var path = require('path');
var webpack = require('webpack');

// var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        matchCenter: './src/pages/matchCenter/index.js',
        InternetCoupon: './src/pages/InternetCoupon/index.js',
        inforCenter: './src/pages/inforCenter/index.js',
        shoppingMall: './src/pages/shoppingMall/index.js',
    },
    output: {
        path: path.join(__dirname, 'dist'),
        publicPath: '/dist/',
        filename: 'js/[name].js',
        chunkFilename: 'js/[id].chunk.js'
    },
    module: {
        loaders: [{
                test: /\.vue$/,
                loader: 'vue-loader',
            }, 
            {
                test: /\.css$/,
                loaders: ['style-loader', 'css-loader'],
            }, 
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.less$/,
                loader: ['style-loader', 'css-loader', 'less-loader'],
            },
              {
                //html模板加载器，可以处理引用的静态资源，默认配置参数attrs=img:src，处理图片的src引用的资源
                //比如你配置，attrs=img:src img:data-src就可以一并处理data-src引用的资源了，就像下面这样
                test: /\.html$/,
                loader: "html-loader"
            }, {

                test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                loader: 'file-loader?name=./fonts/[name].[ext]'
            }, {


                test: /\.(png|jpg|gif)$/,
                loader: 'url-loader?limit=8192&name=./img/[hash].[ext]'
            }
        ]
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery'
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'vendors', // 将公共模块提取，生成名为`vendors`的chunk
            chunks: ['index', 'list', 'about'], //提取哪些模块共有的部分
            minChunks: 3 // 提取至少3个模块共有的部分
        }),
        // new ExtractTextPlugin('css/[name].css'),


        new HtmlWebpackPlugin({
            filename: './pages/matchCenter/index.html',
            template: './src/pages/matchCenter/index.html',
            inject: true,
            chunks: ['pages/matchCenter/index'],
            minify: {
                removeComments: true,
                collapseWhitespace: false
            }
        }),
        new HtmlWebpackPlugin({
            filename: './pages/InternetCoupon/index.html',
            template: './src/pages/InternetCoupon/index.html',
            inject: true,
            chunks: ['pages/InternetCoupon/index'],
            minify: {
                removeComments: true,
                collapseWhitespace: false
            }
        }),
        new HtmlWebpackPlugin({
            filename: './pages/inforCenter/index.html',
            template: './src/pages/inforCenter/index.html',
            inject: true,
            chunks: ['pages/inforCenter/index'],
            minify: {
                removeComments: true,
                collapseWhitespace: false
            }
        }),

        new webpack.HotModuleReplacementPlugin()
    ],

    devServer: {
        contentBase: './',
        host: 'localhost',
        port: 9091,
        inline: true,
        hot: true,
    }
};